package com.cocotingo.snail.dispatcher;

import java.util.LinkedList;
import java.util.List;

class Queue<T> {
	
	private final List<T> queue;
	
	public Queue() {
		queue = new LinkedList<T>();
	}
	
	public void append(T object) {
		synchronized (queue) {
			queue.add(object);
			queue.notify();
		}
	}
	
	public T next() throws InterruptedException {
		synchronized (queue) {
			if (queue.size() == 0) {
				queue.wait();
			}
			return queue.remove(0);
		}
	}
	
	public int size() {
		synchronized (queue) {
			return queue.size();
		}
	}

}
